<!DOCTYPE html>
<html>
<head>
	<title>登录</title>
	<link href="/libs/css/bootstrap.min.css" rel="stylesheet">
	<link href="/libs/css/sweetalert.min.css" rel="stylesheet">
	<script src="/libs/js/jquery.min.js"></script>
	<script src="/libs/js/bootstrap.min.js"></script>
	<script src="/libs/js/sweetalert.min.js"></script>
	<style type="text/css">
		html{
			background-image: url(./assets/bg.jpg);
			background-size: 100% 100%;
			background-repeat: no-repeat;
			background-attachment:fixed;
		}
		.container{
			width: 300px;
			margin: 200px auto 0 auto;
			border-radius: 10px;
			padding: 20px;
			border: 1px solid #ddd;
			background-color: rgba(255,255,255,0.5);
		}
		body{
			background-color: transparent;
		}
		.inputArea{
		}
		h3{
			margin: 20px 0;
		}
		#tips{
			margin-top: 10px;
			text-align: center;
			color: red;
		}
	</style>
</head>
<body>
	<div class="container">
		<h3>新闻网</h3>
		<div>
			<div class="form-group">
				<input type="text" class="form-control inputArea" id="account" placeholder="请输入邮箱" style="margin-bottom: 20px" maxlength="20">
				<input type="password" class="form-control inputArea" id="password" placeholder="请输入密码"  style="margin-bottom: 20px" maxlength="20">
				<input type="password" class="form-control inputArea" id="password2" placeholder="请再次输入密码" maxlength="20">
			</div>
			<div style="text-align: center;margin-top: 50px;">
				<button id="submit" style="width: 100%;" class="btn btn-primary">注册</button>
			</div>
			<p id="tips" style="display: none">注册错误</p>
		</div>
	</div>
	<script type="text/javascript">
		// 获取url中的wpsComment参数
		function getQueryString(name) { 
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
			var r = window.location.search.substr(1).match(reg); 
			if (r != null) return unescape(r[2]); return null; 
		}


		$("#submit").click(function(){
			var account = $("#account").val();
			var password = $("#password").val();
			var password2 = $("#password2").val();
			if (account == undefined || account == "") {
				$("#tips").html("邮箱不能为空");
				$("#tips").show();
			} else if (password == undefined || account == "") {
				$("#tips").html("密码不能为空");
				$("#tips").show();
			} else if (password.length < 10) {
				$("#tips").html("密码不能少于10位");
				$("#tips").show();
			} else if (password !== password2) {
				$("#tips").html("两次输入密码不一");
				$("#tips").show();
			} else {
				$.post("/api/register", {
					account: account,
					password: password
				},function(data,status){
					if (data.success == "ok") {
						swal({ 
							title: "注册成功", 
							text: "现在就去登录", 
							type: "success",
							showCancelButton: false, 
							confirmButtonColor: "#AEDEF4",
							confirmButtonText: "好的", 
							closeOnConfirm: false
						},function(){
							window.location.href = "/login.html?jump="+getQueryString("jump");
						});
					} else {
						$("#tips").html(data.msg);
						$("#tips").show();
					}
				})
			}
		})

	</script>
</body>
</html>